const { defineConfig } = require('@vue/cli-service')
const path = require('path')

function resolve(dir) {
  return path.join(__dirname, dir)
}

module.exports = defineConfig({
  transpileDependencies: true,

  pluginOptions: {
    'style-resources-loader': {
      preProcessor: 'less',
      //引入less语法到各个Vue组件的style标签中使用
      patterns: [
        path.join(__dirname, './src/assets/css/special-effect.less'),
        path.join(__dirname, './src/assets/css/themes-colos.less')
      ]
    }
  },
  devServer: {
    open: true,
    host: '127.0.0.1',
    port: '80',
    hot: 'only',
    proxy: {
      [process.env.VUE_APP_BASE_API]:{
        // target: 'http://112.74.46.107:8080',
        target: 'http://localhost:8080',
        changeOrigin: true,
        pathRewrite: {
          ['^' + process.env.VUE_APP_BASE_API]: ''
        }
      }
    },
    historyApiFallback: true,
    allowedHosts: 'all'
  },
  chainWebpack(config) {

    // set svg-sprite-loader
    config.module
      .rule('svg')
      .exclude.add(resolve('src/assets/icons'))
      .end()
    config.module
      .rule('icons')
      .test(/\.svg$/)
      .include.add(resolve('src/assets/icons'))
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({
        symbolId: 'icon-[name]'
      })
      .end()
  }
})
